home *** CD-ROM | disk | FTP | other *** search
- Path: news.achilles.net!usenet
- From: Pascal Lachance <plachance@xtc-com.com>
- Newsgroups: comp.lang.c++
- Subject: unlucky 13
- Date: Fri, 29 Mar 1996 15:21:22 -0500
- Organization: Achilles Internet Services, Ottawa, ON
- Message-ID: <315C4642.57DA@xtc-com.com>
- NNTP-Posting-Host: 205.233.53.187
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (Win95; I)
-
- Well I guess 13 is not a lucky number after all, after I run this
- program
- it kluncks out at 13. It should start at 20 and then substract one from
- that
- until it reaches 0.
-
- Does anybody know what is wrong with this ?
- If so leave me some mail :)
-
- Thanks
-
-
- #include <stdio.h>
- #include <iostream.h>
- #include <string.h>
- #include <stdlib.h>
- #include <time.h>
-
- struct rec {
- char name[50];
- long money;
- };
-
- void main()
- {
- FILE *f;
- struct rec t_rec;
- int x,y,z;
- int count;
- //create user
-
- f=fopen("money.dat","w");
- strcpy(t_rec.name,"Joe Bob");
- t_rec.money =20;
- fwrite(&t_rec,sizeof(struct rec),1,f);
- fclose(f);
-
-
- while(t_rec.money>0)
- {
- f=fopen("money.dat","r");
- fread(&t_rec,sizeof(struct rec),1,f);
- cout << "After Read,Before Sub money = " << t_rec.money <<
- "\n";
- t_rec.money -= 1;
- cout << "after Sub money = " << t_rec.money << "\n";
- fclose(f);
- f=fopen("money.dat","w");
- fwrite(&t_rec,sizeof(struct rec),1,f);
- cout << "after write money = " <<t_rec.money << "\n";
- cout << "---------------------------------\n\n";
- fclose(f);
-
-
-
- }
- } //end main
-